package com.lancoo.znbkxx;

import android.Manifest;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


import com.example.znbk.znbklibrary.base.BaseActivity;
import com.tt.SkEgnManager;
import com.tt.listener.OnInitEngineListener;
import com.tt.setting.EngineSetting;
import com.tt.widget.PermissionsManager;
import com.tt.widget.PermissionsResultAction;

import znbkBkfx.BkfxMainInforActivity;
import znbkCNtxl.CNtxlActivity;
import wangguolongTest.TestMainActivity;


/*
* 放弃
* */
public class MainActivity extends BaseActivity {

    public void doBusiness() {
        //处理业务操作
        mBtnNextActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                startActivity(TestMainActivity.class);
            }
        });
        mBtnBkfxActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                startActivity(BkfxMainInforActivity.class);
            }
        });
        mBtnBkfxResultActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mBtnNtxlActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                startActivity(CNtxlActivity.class);
            }
        });
        mBtnBkfxZwActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    @Override
    protected int setLayout() {
        return R.layout.activity_main;
    }

    private Button mBtnNextActivity;
    private Button mBtnBkfxActivity,mBtnNtxlActivity;
    private Button mBtnBkfxResultActivity;
    private Button mBtnBkfxZwActivity,mBtnBkfxTkActivity,mBtnBkfxXzActivity;
    @Override
    protected void initView() {

        requestAllPermissions();
        //初始化控件
        mBtnNextActivity = findViewById(R.id.nextActivity);
        //备考复习activity入口
        mBtnBkfxActivity = findViewById(R.id.btn_bkfxActivity);
        //备考复习结果页面activity入口
        mBtnBkfxResultActivity = findViewById(R.id.btn_bkfxResultActivity);
        //难题训练activity入口
        mBtnNtxlActivity = findViewById(R.id.btn_ntxlActivity);
        //作文，填空，选择
        mBtnBkfxZwActivity = findViewById(R.id.btn_zwView);
        mBtnBkfxTkActivity = findViewById(R.id.btn_tkView);
        mBtnBkfxXzActivity = findViewById(R.id.btn_xzView);

        doBusiness();
    }

    private void requestAllPermissions() {
        //初始化语音识别引擎
        final EngineSetting setting = EngineSetting.getInstance(getApplicationContext());
        setting.setVADEnabled(true);
        setting.setOnInitEngineListener(new OnInitEngineListener() {
            @Override
            public void onStartInitEngine() {
                Toast.makeText(getApplicationContext(), "开始初始化引擎", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onInitEngineSuccess() {
                Toast.makeText(getApplicationContext(), "初始化引擎成功", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onInitEngineFailed() {
                Toast.makeText(getApplicationContext(), "初始化引擎失败", Toast.LENGTH_SHORT).show();
            }
        });

        PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(this,
                new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_PHONE_STATE}, new PermissionsResultAction() {

                    @Override
                    public void onGranted() {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                SkEgnManager.getInstance(getApplicationContext()).initCloudEngine("148757611600000f", "2d5356fe1d5f3f13eba43ca48c176647", "userId", setting);
                            }
                        }).start();
                    }

                    @Override
                    public void onDenied(String permission) {

                    }
                });
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        PermissionsManager.getInstance().notifyPermissionsChange(permissions, grantResults);
    }

//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        SkEgnManager.getInstance(this).stopRecord();
//        SkEgnManager.getInstance(this).recycle();
//    }

}